#include <memory>
#include "MessageRoute.hpp"
#include "Server.hpp"

void Usage(const std::string& proc)
{
    std::cout << "Usage error! \n\t" << proc << " local_port" << std::endl;
}

// using func_t = std::function<void (int sfd, const std::string& message, const InetAddr& who)>; 

int main(int argc, const char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERROR);
    }
    // 将日志打印到显示器上
    EnableScreen();

    // 定义消息转发模块
    MessageRoute route;
    
    // 网络部分
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<UdpServer> udp_server = std::make_unique<UdpServer>(port, \
        std::bind(&MessageRoute::Route, &route, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); // C++14

    udp_server->InitServer();
    udp_server->Start();

    return 0;
}
 